package com.tico.common.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.PropertyNamingStrategy;
import com.alibaba.fastjson.serializer.SerializeConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

//@Slf4j
@Component
public class KafkaUtil {

    @Autowired(required = false)
    private KafkaTemplate<String, String> kafkaTemplate;

    public void sendMessage(String topic, String key, String message) {
//        log.info("[KafkaUtil]-sendMessage,kafka消息推送，topic:{}, message:{}", topic, message);
        this.kafkaTemplate.send(topic, key, message);
    }

    public void sendMessage(String topic, String key, Object message, PropertyNamingStrategy strategy) {
        SerializeConfig config = new SerializeConfig();
        config.setPropertyNamingStrategy(strategy);
        sendMessage(topic, key, JSON.toJSONString(message, config));
    }
}
